package com.paomi.client.activity.detail.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.paomi.client.R;
import com.paomi.client.activity.detail.model.TipCommentBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by pc on 2018/3/19.
 * 举报列表适配的列表
 */

public class TipListAdapter extends RecyclerView.Adapter<TipListAdapter.ViewHolder> {
    Context context;
    List<TipCommentBean> mlist;
    Typeface iconface;
    TipListAdapter.OnItemClick onClickListener;

    public void OnItemClick(TipListAdapter.OnItemClick onClickListener) {
        this.onClickListener = onClickListener;
    }


    public TipListAdapter(Context context, List<TipCommentBean> list, Typeface typeface) {
        this.context = context;
        this.mlist = list;
        this.iconface = typeface;
    }

    @Override
    public TipListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new TipListAdapter.ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_tip_list, parent, false));
    }

    @Override
    public void onBindViewHolder(final TipListAdapter.ViewHolder holder, final int position) {
        TipCommentBean ticket = mlist.get(position);
        holder.tip_one.setText(ticket.getValue());
//        holder.tip_one_btn.setTypeface(iconface);
//        if (ticket.getType() == 0) {
//            holder.tip_one_btn.setVisibility(View.GONE);
//            holder.tip_one_btn.setTextColor(context.getResources().getColor(R.color.text_66));
//        } else if (ticket.getType() == 1) {
//            holder.tip_one_btn.setVisibility(View.VISIBLE);
//            holder.tip_one_btn.setTextColor(context.getResources().getColor(R.color.main_color));
//        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onClickListener != null) {
                    for (int i = 0; i < mlist.size(); i++) {
                        if (i == position) {
                            mlist.get(i).setType(1);
                        } else {
                            mlist.get(i).setType(0);
                        }
                    }
                    notifyDataSetChanged();
                    onClickListener.setOnItemClick(holder.itemView, position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tip_one)
        TextView tip_one;
//        @BindView(R.id.tip_one_btn)
//        TextView tip_one_btn;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClick {
        void setOnItemClick(View view, int pos);
    }
}
